c#

您所在的位置:网站首页 241打印纸尺寸设置 没有自定义 c#

c#

2024-07-11 06:37| 来源: 网络整理| 查看: 265

我正在尝试使用 PrintDocument 并设置要打印的纸张尺寸或条码热敏打印机。因为我附近没有打印机,所以我使用的是 Win10 中出现的 Microsoft Print To PDF 选项。

在初始化期间,我有这样的代码: exception during setting custom paper size

如您所见,在这里我尝试为默认纸张尺寸设置自定义纸张尺寸。但是,我不能指定 Kind 属性,因为它是只读的! RawKind 属性没有帮助。

作为替代,我有这样的事件。它也没有帮助。它在预览时正确显示页面布局,但在 PDF 文档中,我观察到默认情况下以 A4 打印的页面。

private void PrintDoc_QueryPageSettings(object sender, QueryPageSettingsEventArgs e) { PageSettings nSettings = new PageSettings(); int properWidthInHundretsOfInches = (int)(handlingClassRef.newconfig.labelParameters.barcodeLabelWidthMM * (1.0 / 25.4) * 100.0); int properHeightInHundretsOfInches = (int)(handlingClassRef.newconfig.labelParameters.barcodeLabelHeightMM * (1.0 / 25.4) * 100.0); nSettings.PaperSize = new PaperSize("label", (int)properWidthInHundretsOfInches, (int)properHeightInHundretsOfInches); e.PageSettings = nSettings; } 我知道问题 How to print with custom paper size in winforms ,但我实际上不明白答案。我应该使用打印机属性 OS 对话框重新配置打印机吗?我宁愿不要求用户以一种或另一种方式修改打印机的设置。另外,我想在打印到 pdf 探索阶段获得适当的结果。

如何在 C# 打印文档中设置和打印自定义纸张尺寸?

编辑:使用该行:

printDoc.DefaultPageSettings.PaperSize = new PaperSize("label", properWidthInHundretsOfInches, properHeightInHundretsOfInches); 没有解决问题。

这是一个结果:

preview is nice and small but printed document is large and has not proper page size

预览很好,很小,但打印的文档很大,页面大小不合适

最佳答案

您可以尝试在 System.Drawing.Printing 下初始化 PaperSize 类,然后您可以指定自定义大小

printDoc.DefaultPageSettings.PaperSize = new PaperSize("MyPaper", 600, 800);

关于c# - 如何在 C# 打印文档中设置和打印自定义纸张尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59753524/



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3